package cn.supermarket.controller;

import cn.supermarket.pojo.dto.StockTimeAddDTO;
import cn.supermarket.pojo.vo.StockDetailedVO;
import cn.supermarket.service.iservice.IStockService;
import cn.supermarket.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@RestController
@RequestMapping("/time")
@Slf4j
@Api(tags = "实时库存")
public class StockTimeController extends BaseController{
    @Autowired
    private IStockService stockService;

    @ApiOperation("添加库存条目")
    @PostMapping("/addNew")
    public JsonResult<Void> addNew(StockTimeAddDTO stockTimeAddDTO){
        stockService.addNew(stockTimeAddDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除库存条目")
    @GetMapping("/delete")
    public JsonResult<Void>delete(Long productId){
        stockService.deleteById(productId);
        return JsonResult.ok();
    }

    @ApiOperation("根据productId查询查询详情")
    @GetMapping("/getdetailed")
    public JsonResult<StockDetailedVO> selectStockDetailedVOByProductId(Long productId){
        StockDetailedVO stockDetailedVO = stockService.selectStockDetailedVOByProductId(productId);
       return JsonResult.ok(stockDetailedVO);
    }

    @ApiOperation("查询所有")
    @GetMapping("/select/all")
    public JsonResult<List<StockDetailedVO>> selectAll(){
        List<StockDetailedVO> stockDetailedVOS = stockService.selectAll();
        return JsonResult.ok(stockDetailedVOS);
    }

    @ApiOperation("查询库存预警")
    @GetMapping("/select/line")
    public JsonResult<List<StockDetailedVO>> selectByLine(){
        List<StockDetailedVO> stockDetailedVOS = stockService.selectByWarningLine();
        return JsonResult.ok(stockDetailedVOS);
    }

    @ApiOperation("根据商品分d查询")
    @GetMapping("/select/category")
    public JsonResult<List<StockDetailedVO>> selectByCategoryId(Long categoryId){
        List<StockDetailedVO> stockDetailedVOS = stockService.selectByCategoryId(categoryId);
        return JsonResult.ok(stockDetailedVOS);
    }

}
